/*
 * DA7.c
 *
 * Created: 2014/4/25 10:29:44
 *  Author: Raymond
 */ 

#define F_CPU 1000000UL
#include <util/delay.h>
#include <stdio.h>
#include <avr/pgmspace.h>
#include <avr/io.h>
#include "nokia5110.h"
#include "main.h"


int main()
{

//initialize ADC conversion	
	 DDRC =0x00; //set PDC for ADC output
	 ADCSRA =0x8f; // enable ADC with prescaler 128
	 ADMUX =0xc0;

	//initialize  LCD
	LcdInit();

	//display dark image (testing)
	LcdContrast(0x7F);
	_delay_ms(1000);
	LcdClear();

	//adjust proper contrast
	LcdContrast(0x3A);
	_delay_ms(1000);
	LcdClear();
	
	//custom please wait image
	LcdImage(waitImage);
	LcdUpdate();
	_delay_ms(3000);

	while (1)
	{
		uint8_t ADC_value_L=ADCL;
		uint16_t tempval=(ADCH<<8)|ADC_value_L;

		uint16_t temp1 = tempval%10;
		uint16_t temp2 = tempval%100;
		uint16_t temp3 = tempval%1000;
		uint16_t temp4 = tempval%10000;
		char buffer[5],buffer2[15];
		sprintf(buffer, "%d%d.%d%d ", temp1, temp2, temp3, temp4);
		sprintf(buffer2, "Fahrenheit");
		//display string
		LcdClear();
		LcdGotoXYFont(1,1);
		LcdFStr(FONT_1X,(unsigned char*)buffer);
		LcdGotoXYFont(1,2);
		LcdFStr(FONT_1X,(unsigned char*)buffer2);
		LcdUpdate();
		_delay_ms(1000);
	}
	return 0;
}
